home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / term / vltj5867.lha / VLT / rexx / VLTPhoneDial.rexx < prev    next >
OS/2 REXX Batch file  |  1994-03-27  |  7KB  |  251 lines

  1. /** VLTPhoneDial.rexx
  2. *
  3. *   This program is called from the VLTPhoneBook program when the
  4. *   Start Dialing Sequence buttom is hit. It then finds the "dial_file"
  5. *   and dials the first entry in it. Then it will try establish a
  6. *   connection, and if it works, it will wait until the user clicks on
  7. *   "Resume Dialing Sequence". If there is no connection, it will continue
  8. *   on to the next entry on the list and try all entries until a connection
  9. *   is established. The looping will continue until all connections have
  10. *   been dialed once, or until the "Abort Dialing Sequence" button is
  11. *   hit.
  12. *
  13. *   This routine may also be run separately (i.e. it does not have to
  14. *   be called from VLTPhoneBook). But it must be called from inside
  15. *   VLT. Not however the following:
  16. *
  17. *   For this function, if it is run under "AREXX", the port name of VLT
  18. *   is given as an argument, because when run under AREXX, the default
  19. *   port name is not that of the application.
  20. *
  21. *   By W.G.J. Langeveld, February 1992.
  22. *
  23. **/
  24. parse arg vltport
  25. /*
  26. *   Add libraries if necessary
  27. */
  28. if show("l", "rexxarplib.library") = 0 then do
  29.    check = addlib('rexxsupport.library', 0, -30, 0)
  30.    check = addlib('rexxarplib.library',  0, -30, 0)
  31. end
  32. /*
  33. *   First define some text strings and procedures. Here we assume
  34. *   a Hayes compatible modem. If you have a different modem, you should
  35. *   be able to change just the following three strings.
  36. *
  37. *   Here's a set of responses that is given by Hayes modems:
  38. */
  39. response     = "OK"
  40. connectstr   = "CONNECT"
  41. busystr      = "BUSY"
  42. nocarrierstr = "NO CARRIER"
  43. /*
  44. *   Here is a hangup script that may work for Hayes modems.
  45. *   You could also just drop DTR if that works for you:
  46. *
  47. *   hangupscript = "hangup"
  48. */
  49. hangupscript = "$vltphone_wait: on (OK) continue; send (+++); delay 2; "
  50. hangupscript = hangupscript || "send (ATH*R); delay 15; on (OK) (); send (*R*R)"
  51. /*
  52. *   This script I use to get the modem in line after changing parity.
  53. *   You may be able to get away with not doing anything, like this:
  54. *
  55. *   retrainscript = ""
  56. */
  57. retrainscript = "$vltphone_wait: on (OK) exit; send (AT*R); $1: delay .5; "
  58. retrainscript = retrainscript || "send (AT*R); goto $1"
  59.  
  60.  
  61.  
  62. /*
  63. *   Okay, to the real work. First set the port to that of this invocation
  64. *   of VLT.
  65. */
  66. address value vltport
  67.  
  68. cols = ScreenCols(vltport)
  69. if cols == -1 then do
  70.    vltscreen = ""
  71.    cols = ScreenCols()
  72.    rows = ScreenRows()
  73. end
  74. else do
  75.    vltscreen = vltport
  76.    rows = ScreenRows(vltscreen)
  77. end
  78. /*
  79. *   Check if we're set up correctly without requesters coming up.
  80. *   If not, call the setup program
  81. */
  82. call pragma('W', 'NULL')
  83.  
  84. if ~exists("VLTPhoneBook:") then do
  85.    "@VLTPhoneSetup.rexx"
  86.    exit
  87. end
  88. /*
  89. *   Open the dial file
  90. */
  91. if open(input, "VLTPhoneBook:T/dial_file", "r") = 0 then do
  92.    "message (Couldn't read dial file); delay 1.5; message"
  93.    exit
  94. end
  95. /*
  96. *   Read the dial file
  97. */
  98. do i = 1
  99.    files.i.filename = readln(input)
  100.    files.i.done = 0
  101.    if eof(input) ~= 0 then leave
  102. end
  103.  
  104. call close(input)
  105.  
  106. files.0 = i - 1
  107. if files.0 = 0 then do
  108.    "message (Dial file has no entries)"
  109.    exit
  110. end
  111. /*
  112. *   Read all the phonebook files that are called for in the dial file
  113. */
  114. do i = 1 to files.0
  115.    if open(input, files.i.filename, "r") = 0 then do
  116.       "message (Couldn't read file "files.i.filename")"
  117.       exit
  118.    end
  119.  
  120.    files.i.name    = readln(input)
  121.    files.i.address = readln(input)
  122.    files.i.city    = readln(input)
  123.    files.i.phone   = strip(readln(input))
  124.    files.i.modem   = strip(readln(input))
  125.    files.i.baud    = strip(readln(input))
  126.    files.i.parity  = strip(readln(input))
  127.    files.i.fcmds   = strip(readln(input))
  128.    files.i.lcmds   = strip(readln(input))
  129.    files.i.notes   = readln(input)
  130.  
  131.    call close(input)
  132. end
  133. /*
  134. *   Main dialing loop
  135. */
  136. i = 1
  137. donefiles = 0
  138.  
  139. do forever
  140.    if files.i.done = 0 then do
  141. /*
  142. *   Preset the cancel flag to something, announce who we're calling,
  143. *   set baud and parity. Then do the first (predial) set of commands
  144. *   if any.
  145. */
  146.       vlt.CANCELFLAG = "start"
  147.       if length(files.i.baud)   > 0 then "baud   "files.i.baud
  148.       if length(files.i.parity) > 0 then "parity "files.i.parity
  149.       if length(files.i.fcmds)  > 0 then ""files.i.fcmds
  150. /*
  151. *   We may have changed parity, and the modem may need some time.
  152. */
  153.       if retrainscript ~= "" then retrainscript
  154.       if upper(vlt.CANCELFLAG) = "ABORT" then do
  155.          "message (Aborted!)"
  156.          exit 0
  157.       end
  158.       "message; message (Dialing "files.i.name"...)"
  159. /*
  160. *   Send the modem string if any.
  161. */
  162.       if length(files.i.modem)  > 0 then do
  163.          "$vltphone_wait: on ("response") continue; send  ("files.i.modem"*R*N); delay 5"
  164.          if upper(vlt.CANCELFLAG) = "ABORT" then do
  165.             "message (Aborted!)"
  166.             exit 0
  167.          end
  168.       end
  169. /*
  170. *   Set up the "CONNECT" trap. Make it start the second (postdial)
  171. *   set of comamnds if there are any.
  172. */
  173.       if length(files.i.script) > 0 then do
  174.          "trap add 314 install ("connectstr") ("files.i.lcmds"; cancel $vltphone_wait connect)"
  175.       end
  176.       else do
  177.          "trap add 314 install ("connectstr") (cancel $vltphone_wait connect)"
  178.       end
  179. /*
  180. *   Set up the BUSY and NO CARRIER traps. Note the use of the new feature
  181. *   of the CANCEL command.
  182. */
  183.       "trap add 315 install ("busystr")      (cancel $vltphone_wait busy)"
  184.       "trap add 316 install ("nocarrierstr") (cancel $vltphone_wait nocarrier)"
  185. /*
  186. *   Send dial string and wait until the "pause" gets cancelled
  187. */
  188.       if length(files.i.phone) > 0 then do
  189.          "$vltphone_wait: send ("files.i.phone"*r); pause"
  190.       end
  191.       else do
  192.          "$vltphone_wait: pause"
  193.       end
  194. /*
  195. *   We got cancelled. See which event cancelled us.
  196. */
  197.       event = vlt.CANCELFLAG
  198. /*
  199. *   Remove the traps but only the ones we used.
  200. */
  201.       "trap remove 314 315 316"
  202. /*
  203. *   If we got connected, close the panel if it exists, increment the
  204. *   number of successful connections.
  205. */
  206.       if upper(event) = "CONNECT" then do
  207.          files.i.done = 1
  208.  
  209.          if showlist('p', VLTPHONEBOOK) ~= 0 then do
  210.             "message"
  211.             address VLTPHONEBOOK quit
  212.          end
  213.  
  214.          donefiles = donefiles + 1
  215.          if donefiles = files.0 then exit 0
  216. /*
  217. *   Wait until we get called again.
  218. */
  219.          "$vltphone_wait: pause"
  220.          event = vlt.CANCELFLAG
  221.       end
  222. /*
  223. *   If we need to resume, send a few hangups.
  224. */
  225.       if upper(event) = "RESUME" then hangupscript
  226. /*
  227. *   Check if we got an abort event. If so, quit.
  228. */
  229.       if upper(event) = "ABORT" then do
  230.          "message (Aborted!)"
  231.          exit 0
  232.       end
  233. /*
  234. *   If the hangupscript was interrupted, also abort
  235. */
  236.       if upper(vlt.CANCELFLAG) = "ABORT" then do
  237.          "message (Aborted!)"
  238.          exit 0
  239.       end
  240.    end
  241. /*
  242. *   Increment the list pointer, roll back to 1 if needed
  243. */
  244.    i = i + 1
  245.    if i > files.0 then i = 1
  246. end
  247.  
  248. /*
  249. *   We don't get here
  250. */
  251.